import HTMLParser
import urllib
import re
import string


urlString = "http://www.dix.dk/aslist/"
urlText = []
pathOut = "ixp_members.txt"


class Parse51 (HTMLParser.HTMLParser):
    
    check = False
    
    def handle_starttag (self, tag, attrs):
        if tag == "br" or tag == "span":
            self.check = True
    
    def handle_data (self, data):
        if self.check == True:
            m = re.match("^\s*(\d+(/\d+)*) - .+$",data)
            if m:
                data = string.split(m.group(1),"/")
                for i in data:
                    if i not in urlText:
                        urlText.append(i)
            self.check = False


lparser = Parse51()
lparser.feed(urllib.urlopen(urlString).read())
fileOut = open(pathOut, "a")
for item in urlText:
    #print item # debug
    print >> fileOut, "51 %s" % item
fileOut.close()